package com.liferay.portal.events;

import java.util.List;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.Address;
import com.liferay.portal.model.Phone;
import com.liferay.portal.model.User;

public class LandingPageHelperUtil {
	public static boolean areCoordinatesSet(User user) {
		
		boolean coordinatesSet = false;
		
		List<Address> addresses = null;
		try {
			addresses = user.getAddresses();
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if (Validator.isNull(addresses) || addresses.isEmpty()) return false;
		
		boolean checkForPhone = false;
		
		for (Address address: addresses) {
			if (address.isPrimary()) {
				checkForPhone = true;
				break;
			}
		}
		
		if (checkForPhone) {
			
			List<Phone> phones = null;
			try {
				phones = user.getPhones();
			} catch (SystemException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			if (Validator.isNull(phones) || phones.isEmpty()) return false;
			
			for (Phone phone : phones) {
				if (phone.isPrimary()) {
					coordinatesSet = true;
					break;
				}
			}
		}
			
		return coordinatesSet;
	}
}